﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Admin.Controls
{
    public partial class ListDuAn : System.Web.UI.UserControl
    {
        public int count;
        ListItem lt;
        DataTable dt;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                count = 1;
                Cate1.Items.Clear();
                dt = DAL.DCollector.DBCollector.Instance.StoredSelectAllTableWhereID("tbl_Category", "Category_ID2 "," 19");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    lt = new ListItem(dt.Rows[i]["Category_Name"].ToString(), dt.Rows[i]["Category_ID1"].ToString());
                    Cate1.Items.Add(lt);
                }
                int catid = Convert.ToInt32(Cate1.SelectedValue);
                rpt_news.DataSource = DAL.DCollector.DBCollector.Instance.StoredSelectAllTableWhereIDOrderBySort("tbl_DuAn", " Category_ID1  ", catid.ToString(),"DuAn_Date","DESC");

                rpt_news.DataBind();
            }
            catch (Exception)
            {
                Response.Redirect("/Admin/error.htm");
            }
        }

        protected void Cate1_SelectedIndexChanged(object sender, EventArgs e)
        {
            count = 1;
            int index = Cate1.SelectedIndex;
            if (index > 0)
            {
                int id = Convert.ToInt32(Cate1.SelectedValue);
                dt = DAL.DCollector.DBCollector.Instance.CallStored("callstored", "SELECT * FROM tbl_DuAn WHERE Category_ID1 = " + id, true);
                rpt_news.DataSource = dt;
                rpt_news.DataBind();
            }
        }

        protected void rpt_news_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "delete")
            {
                // Xoa
                int id = Convert.ToInt32(e.CommandArgument.ToString());
                DAL.DCollector.DBCollector.Instance.StoredProcedureDeleteByRows("tbl_DuAn", "DuAn_ID", id.ToString());
                Response.Redirect("/Admin/Index.aspx?panel=3&sub=30");
            }
        }
    }
}